<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>边框动画</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    html, body {
      background: #333;
    }
    .border {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 200px;
      height: 200px;
      border: 1px solid #888;
      background: #444;
    }
    .border > div {
      position: absolute;
      left: -1px;
      top: -1px;
      width: 100%;
      height: 100%;
      transition: .5s;
    }
    .border:hover > .border-top-bottom{
      transform: rotateY(0);
    }
    .border:hover > .border-left-right{
      transform: rotateX(0);
    }
    .border-top-bottom {
      border: 1px solid transparent;
      border-top: 1px solid gold;
      border-bottom: 1px solid gold;
      transform: rotateY(90deg);
    }
    .border-left-right {
      border: 1px solid transparent;
      border-left: 1px solid gold;
      border-right: 1px solid gold;
      transform: rotateX(90deg);
    }
  </style>
</head>
<body>
  <div class="border">
    <div class="border-top-bottom"></div>
    <div class="border-left-right"></div>
  </div>
</body>
</html>